﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Threading;

namespace DemoApp
{
    public class WPFUIVisualizerService : IUIVisualizerService
    {
 
        #region Public Methods
        /// <summary>
        /// This method displays a modal dialog associated with the given key.
        /// </summary>
        /// <param name="dataContextForPopup">Object state to associate with the dialog</param>
        /// <returns>True/False if UI is displayed.</returns>
        public bool? ShowDialog(object dataContextForPopup)
        {
            if (!System.Windows.Interop.BrowserInteropHelper.IsBrowserHosted)
            {
                PopupWindow win = new PopupWindow();
                win.DataContext = dataContextForPopup;
                win.Owner = Application.Current.MainWindow;
                if (win != null)
                    return win.ShowDialog();
            }
            else
            {
                PopupPage page = new PopupPage();
                page.DataContext = dataContextForPopup;
                if (page != null)
                    return page.ShowDialog();
            }

            return false;
        }

        public bool? ShowListDialog(Dictionary<int, string> dataContext, out int selectedComponent)
        {
            if (!System.Windows.Interop.BrowserInteropHelper.IsBrowserHosted)
            {
                PopupListWindow win = new PopupListWindow(dataContext);
                win.Owner = Application.Current.MainWindow;
                
                if (win != null)
                {
                    bool? retval = win.ShowDialog();
                    selectedComponent = win.getSelectedComponent();
                    return retval;
                }
            }
            else
            {
                PopupListPage page = new PopupListPage(dataContext);
                if (page != null)
                {
                    bool? retval = page.ShowDialog();
                    selectedComponent = page.getSelectedComponent();
                    return retval;
                }
            }

            selectedComponent = 0;
            return false;
        }

        public bool? ShowEditDialog(ref Dictionary<int, string> language, ref List<string> methodNames, ref List<string> methodCodes)
        {
            if (!System.Windows.Interop.BrowserInteropHelper.IsBrowserHosted)
            {
                PopupEditWindow win = new PopupEditWindow(ref language, ref methodNames, ref methodCodes);
                win.Owner = Application.Current.MainWindow;
                if (win != null)
                    return win.ShowDialog();
            }
            else
            {
                PopupEditPage page = new PopupEditPage(ref language, ref methodNames, ref methodCodes);
                if (page != null)
                    return page.ShowDialog();
            }

            return false;
        }
        #endregion

      
    }
}
